package com.wrench.elevator.install.service;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import org.springframework.ui.ModelMap;

import wrench.elevator.install.util.WrenchElevatorInstallException;
import wrench.elevator.install.util.WrenchElevatorInstallUtil;

import com.wrench.elevator.install.constant.Result;
import com.wrench.elevator.install.dao.ZhuangDao;
import com.wrench.elevator.install.domain.Zhuang;


@Component
public class ZhuangService
{
    @Resource
    private ZhuangDao dao;
    
    private static final Logger logger = LoggerFactory.getLogger(ZhuangService.class);
    
    
    
    /**
     * 根据小区ID获取幢列表
     */
    public void loadZhuangList(String building_id, ModelMap params)
     throws WrenchElevatorInstallException
    {
        if (WrenchElevatorInstallUtil.hasNull(building_id, params))
        {
            logger.error("==> param is not found , building_id = {} , params = {} ",
                building_id,
                params);
            throw new WrenchElevatorInstallException(Result.PARAM_IS_NOT_FOUND_CODE, Result.PARAM_IS_NOT_FOUND_MESSAGE);
        }
        /*if (!WrenchElevatorInstallUtil.areInt(building_id))
        {
            logger.error("==> string is not int type , building_id = {}  ", building_id);
            throw new WrenchElevatorInstallException(Result.STRING_IS_NOT_INT_TYPE_CODE, Result.STRING_IS_NOT_INT_TYPE_MESSAGE);
        }*/
        
        List<Zhuang> zhuangList = null;
        
        try
        {
            zhuangList = dao.loadZhuangList(building_id);
        }
        catch (Exception e)
        {
            logger.error("==> dao.loadZhuangList(building_id) execute error , building_id = {} , error = {}  ",
                building_id,
                e);
            throw new WrenchElevatorInstallException(Result.DB_ERROR_CODE, Result.DB_ERROR_MESSAGE);
        }
        logger.debug("==> dao.loadZhuangList(building_id) execute success , building_id = {}  ", 
            building_id);
        params.put("zhuangList", zhuangList);
    }
    
    
}
